package com.emplartec.adf.evaluaciones.model.model.views.beans;

import javax.el.ExpressionFactory;

import javax.el.ValueExpression;

import javax.faces.context.FacesContext;

import oracle.jbo.server.ViewRowImpl;


public class ValueHolder {
    private boolean enableEditing = false;
    private ViewRowImpl SelectedEmploye;
    
    private boolean editAction = false;
    private boolean createAction = false;
    private boolean deleteAction = false;
    
    
    public ValueHolder() {
    }

    public void setEnableEditing(boolean enableEditing) {
        this.enableEditing = enableEditing;
    }

    public boolean isEnableEditing() {
        FacesContext ctx= FacesContext.getCurrentInstance();
        ExpressionFactory  ef=ctx.getApplication().getExpressionFactory();
        ValueExpression ve= ef.createValueExpression(ctx.getELContext(), "#{row.idEmpleado}", String.class);
        
        String idEmmpleado=(String)ve.getValue(ctx.getELContext());
        
        if(this.getSelectedEmploye()!=null){
            this.enableEditing=getSelectedEmploye().getAttribute("idEmpleado").equals(idEmmpleado);
        }
        
        return enableEditing;
    }

    /**
     * @param newSelectedEmploye
     */
    public void setSelectedEmploye(ViewRowImpl newSelectedEmploye) {
        this.SelectedEmploye = newSelectedEmploye;
        if(this.SelectedEmploye !=null){
            this.editAction=true;
        }else{
            this.editAction=false;
            this.createAction=false;
            this.deleteAction=false;
            }
    }

    public ViewRowImpl getSelectedEmploye() {
        return SelectedEmploye;
    }

    public void setEditAction(boolean editAction) {
        this.editAction = editAction;
    }

    public boolean isEditAction() {
        return editAction;
    }

    public void setCreateAction(boolean createAction) {
        this.createAction = createAction;
    }

    public boolean isCreateAction() {
        return createAction;
    }

    public void setDeleteAction(boolean deleteAction) {
        this.deleteAction = deleteAction;
    }

    public boolean isDeleteAction() {
        return deleteAction;
    }
}
